home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / Chef ƒ 1.1 / Chef code ƒ / chef meat.c < prev    next >
Text File  |  1994-02-16  |  6KB  |  311 lines

  1. /**********************************************************************\
  2.  
  3. File:        chef meat.c
  4.  
  5. Purpose:    This module handles the actual conversion to Swedish Chef.
  6.  
  7.  
  8. Chef -=- convert text to Swedish chef talk
  9. Copyright ©1994, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "chef meat.h"
  29. #include "program globals.h"
  30.  
  31. Boolean            gInWord;
  32. Boolean            gSeenI;
  33. unsigned long    gInputOffset;
  34. unsigned long    gOutputOffset;
  35. Ptr                gInputBuffer;
  36. Ptr                gOutputBuffer;
  37. Boolean            gInputNeedsUpdate;
  38. Boolean            gOutputNeedsUpdate;
  39. unsigned long    gAbsoluteOffset;
  40. unsigned long    gInputLength;
  41. Boolean            gSeenBackslash;
  42. int                gCurlyLevel;
  43.  
  44. void ConvertIt(void)
  45. {
  46.     char            oneChar;
  47.     
  48.     if (gUseRTF)
  49.     {
  50.         oneChar=ThisChar();
  51.         if ((oneChar=='}') && (gCurlyLevel>0))
  52.             gCurlyLevel--;
  53.         else if (oneChar=='{')
  54.             gCurlyLevel++;
  55.         
  56.         if (oneChar==0x5c)
  57.             gSeenBackslash=TRUE;
  58.         
  59.         if ((gCurlyLevel>2) || (gSeenBackslash))
  60.         {
  61.             StoreChar(oneChar);
  62.             InputPlus(1);
  63.             if ((oneChar==' ') || (IsNumeric(oneChar)))
  64.                 gSeenBackslash=FALSE;
  65.             return;
  66.         }
  67.     }
  68.     
  69.     oneChar=(ThisChar())|0x20;
  70.     
  71.     if ((ThisChar()=='.') && (NextChar(1)==0x0d))
  72.     {
  73.         gInWord=gSeenI=FALSE;
  74.         StoreChar('.');
  75.         StoreChar(0x0d);
  76.         StoreString("\pBork Bork Bork!");
  77.         InputPlus(1);
  78.         return;
  79.     }
  80.     
  81.     if (!IsAlpha(ThisChar()))
  82.     {
  83.         gInWord=gSeenI=FALSE;
  84.         StoreChar(ThisChar());
  85.         InputPlus(1);
  86.         return;
  87.     }
  88.     
  89.     if ((!gInWord) && (oneChar=='b') && (NextChar(1)=='o')
  90.             && (NextChar(2)=='r') && (NextChar(3)=='k'))
  91.     {
  92.         gInWord=TRUE;
  93.         StoreChar(ThisChar());
  94.         StoreString("\pork");
  95.         InputPlus(4);
  96.         return;
  97.     }
  98.     
  99.     if ((oneChar=='a') && (NextChar(1)=='n'))
  100.     {
  101.         gInWord=TRUE;
  102.         StoreChar(ThisChar()+'u'-'a');
  103.         StoreChar('n');
  104.         InputPlus(2);
  105.         return;
  106.     }
  107.     
  108.     if ((oneChar=='a') && (NextChar(1)=='u'))
  109.     {
  110.         gInWord=TRUE;
  111.         StoreChar(ThisChar()+'o'-'a');
  112.         StoreChar('o');
  113.         InputPlus(2);
  114.         return;
  115.     }
  116.     
  117.     if ((oneChar=='a') && (IsAlpha(NextChar(1))))
  118.     {
  119.         gInWord=TRUE;
  120.         StoreChar(ThisChar()+'e'-'a');
  121.         InputPlus(1);
  122.         return;
  123.     }
  124.     
  125.     if ((ThisChar()=='e') && (NextChar(1)=='n') && (!IsAlpha(NextChar(2))))
  126.     {
  127.         gInWord=TRUE;
  128.         StoreString("\pee");
  129.         InputPlus(2);
  130.         return;
  131.     }
  132.     
  133.     if ((gInWord) && (ThisChar()=='e') && (NextChar(1)=='w'))
  134.     {
  135.         StoreString("\poo");
  136.         InputPlus(2);
  137.         return;
  138.     }
  139.     
  140.     if ((gInWord) && (ThisChar()=='e') && (!IsAlpha(NextChar(1))))
  141.     {
  142.         StoreString("\pe-a");
  143.         InputPlus(1);
  144.         return;
  145.     }
  146.     
  147.     if ((!gInWord) && (oneChar=='e'))
  148.     {
  149.         gInWord=TRUE;
  150.         StoreChar(ThisChar()+'i'-'e');
  151.         InputPlus(1);
  152.         return;
  153.     }
  154.     
  155.     if ((gInWord) && (ThisChar()=='f'))
  156.     {
  157.         StoreString("\pff");
  158.         InputPlus(1);
  159.         return;
  160.     }
  161.     
  162.     if ((gInWord) && (ThisChar()=='i') && (NextChar(1)=='r'))
  163.     {
  164.         StoreString("\pur");
  165.         InputPlus(2);
  166.         return;
  167.     }
  168.     
  169.     if ((gInWord) && (ThisChar()=='i'))
  170.     {
  171.         if (gSeenI)
  172.             StoreChar('i');
  173.         else
  174.             StoreString("\pee");
  175.         gSeenI=TRUE;
  176.         InputPlus(1);
  177.         return;
  178.     }
  179.     
  180.     if ((gInWord) && (ThisChar()=='o') && (NextChar(1)=='w'))
  181.     {
  182.         StoreString("\poo");
  183.         InputPlus(2);
  184.         return;
  185.     }
  186.     
  187.     if ((!gInWord) && (oneChar=='o'))
  188.     {
  189.         gInWord=TRUE;
  190.         StoreChar(ThisChar());
  191.         StoreChar(((oneChar=='O') && (IsUpperAlpha(NextChar(1)))) ? 'O' : 'o');
  192.         InputPlus(1);
  193.         return;
  194.     }
  195.     
  196.     if ((gInWord) && (ThisChar()=='o'))
  197.     {
  198.         StoreChar('u');
  199.         InputPlus(1);
  200.         return;
  201.     }
  202.     
  203.     if ((oneChar=='t') && (NextChar(1)=='h') && (NextChar(2)=='e'))
  204.     {
  205.         gInWord=TRUE;
  206.         StoreChar(ThisChar()+'z'-'t');
  207.         StoreString("\pee");
  208.         InputPlus(3);
  209.         return;
  210.     }
  211.     
  212.     if ((ThisChar()=='t') && (NextChar(1)=='h') && (!IsAlpha(NextChar(2))))
  213.     {
  214.         gInWord=TRUE;
  215.         StoreChar('t');
  216.         InputPlus(2);
  217.         return;
  218.     }
  219.     
  220.     if ((gInWord) && (ThisChar()=='t') && (NextChar(1)=='i') && (NextChar(2)=='o') && (NextChar(3)=='n'))
  221.     {
  222.         gInWord=TRUE;
  223.         StoreString("\pshun");
  224.         InputPlus(4);
  225.         return;
  226.     }
  227.     
  228.     if ((gInWord) && (oneChar=='u'))
  229.     {
  230.         gInWord=TRUE;
  231.         StoreChar(ThisChar()+'o'-'u');
  232.         StoreChar((IsUpperAlpha(NextChar(1))) ? 'O' : 'o');
  233.         InputPlus(1);
  234.         return;
  235.     }
  236.     
  237.     if (oneChar=='v')
  238.     {
  239.         gInWord=TRUE;
  240.         StoreChar(ThisChar()+'f'-'v');
  241.         InputPlus(1);
  242.         return;
  243.     }
  244.     
  245.     if (oneChar=='w')
  246.     {
  247.         gInWord=TRUE;
  248.         StoreChar(ThisChar()+'v'-'w');
  249.         InputPlus(1);
  250.         return;
  251.     }
  252.     
  253.     gInWord=TRUE;
  254.     StoreChar(ThisChar());
  255.     InputPlus(1);
  256. }
  257.  
  258. char ThisChar(void)
  259. {
  260.     if (gInputOffset>=INPUT_BUFFER_MAX)
  261.         gInputNeedsUpdate=TRUE;
  262.     if (gAbsoluteOffset>=gInputLength)
  263.         return 0x00;
  264.     else
  265.         return *((char*)((long)gInputBuffer+gInputOffset));
  266. }
  267.  
  268. char NextChar(int howmany)
  269. {
  270.     if (gAbsoluteOffset+howmany>=gInputLength)
  271.         return 0x00;
  272.     else
  273.         return *((char*)((long)gInputBuffer+gInputOffset+howmany));
  274. }
  275.  
  276. Boolean IsAlpha(char thisChar)
  277. {
  278.     return ((((thisChar|0x20)>='a') && ((thisChar|0x20)<='z')) || (thisChar==0x27));
  279. }
  280.  
  281. Boolean IsUpperAlpha(char thisChar)
  282. {
  283.     return (((thisChar>='A') && (thisChar<='Z')) || (thisChar==0x27));
  284. }
  285.  
  286. Boolean IsNumeric(char thisChar)
  287. {
  288.     return ((thisChar>='0') && (thisChar<='9'));
  289. }
  290.  
  291. void StoreChar(char thisChar)
  292. {
  293.     *((char*)((long)gOutputBuffer+(gOutputOffset++)))=thisChar;
  294.     if (gOutputOffset>=OUTPUT_BUFFER_MAX)
  295.         gOutputNeedsUpdate=TRUE;
  296. }
  297.  
  298. void StoreString(Str255 thisString)
  299. {
  300.     int                i;
  301.     
  302.     for (i=1; i<=thisString[0]; i++)
  303.         StoreChar(thisString[i]);
  304. }
  305.  
  306. void InputPlus(int howmany)
  307. {
  308.     gInputOffset+=howmany;
  309.     gAbsoluteOffset+=howmany;
  310. }
  311.